package com.ybc.chinese.utils;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

/**
 * <p><p/>
 * Created by Yubch on 17/2/18.
 */
public class ImageUtil {
    public static void displayPic(Context context, ImageView view, String url, int holderId) {
        Glide.with(context)
                .load(url)
                .placeholder(holderId)  //默认图片
                .into(view);
    }

    public static void displayPic(Context context, ImageView view, String url) {
        if (!TextUtils.isEmpty(url)) {
            Glide.with(context)
                    .load(url)
                    .into(view);
        }
    }

    /**
     * 加载gif
     * @param context
     * @param view
     * @param url
     */
    public static void displayGif(Context context, ImageView view, String url) {
        if (!TextUtils.isEmpty(url)) {
            Glide.with(context)
                    .load(url)
                    .asGif()
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(view);
        }
    }

    /**
     * 加载gif
     * @param context
     * @param view
     * @param url
     */
    public static void displayGif(Context context, ImageView view, String url, int holderId) {
        if (!TextUtils.isEmpty(url)) {
            Glide.with(context)
                    .load(url)
                    .asGif()
                    .placeholder(holderId)
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(view);
        }
    }

}
